<template>
  <div>
    <van-address-edit :area-list="areaList" show-delete show-set-default show-search-result :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave" @delete="onDelete"
      @change-detail="onChangeDetail" 
      />
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import router from '@/router';
export default defineComponent({
  name: 'AddOrSet'
})
</script>
<script lang="ts" setup>
import { areaList } from '@vant/area-data';
import { ref } from 'vue';
import { showToast } from 'vant';
import cartApi from "@/api/cartList";
import type { UserAddressData } from "@/api/cartList";
const address = ref<UserAddressData[]>([]);
const getAddress = async () => {
  const res = await cartApi.getUserAddress();
  address.value = res;
  // console.log(res);
};
const searchResult = ref([]);
// const show = ref(true)
const onSave = (val: any) => {
router.push({
    name: "address",
  });

  // console.log(val);
  const address = val.city + val.county + val.addressDetail
  // console.log(val);
  const obj = {
    "name": val.name,
    "tel": val.tel,
    "isDefault": val.isDefault,
    "address": address
  }
  localStorage.setItem('address',JSON.stringify(obj))
  // address.value.push(obj)
  
}
const onDelete = () => showToast('delete');
const onChangeDetail = (val: any) => {
  if (val) {
    searchResult.value = [];
  } else {
    searchResult.value = [];
  }
};
</script>
  
<style lang="less" scoped></style>
  